package com.msb.spring;

import java.lang.reflect.Field;

public class Test2 {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        UserController userController = new UserController();
        Class<? extends UserController> clazz = userController.getClass();

        //获取所有的属性值
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field : declaredFields) {
            Autowired annotation = field.getAnnotation(Autowired.class);
            if (annotation != null) {
                field.setAccessible(true);
                //获取类型,方便创建具体对象
                Class<?> type = field.getType();
                Object o = type.newInstance();
                field.set(userController,o);
            }
        }

        System.out.println(userController.getUserService());
    }
}
